package com.hzhk.happyrent.ui.adapter.rent;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hzhk.happyrent.App;
import com.hzhk.happyrent.Constants;
import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.card.CardHotModel;
import com.hzhk.happyrent.bean.rent.ProductListModel;
import com.hzhk.happyrent.ui.activity.rent.ProductDetailsActivity;
import com.hzhk.happyrent.ui.adapter.BaseAdapter;
import com.hzhk.happyrent.utils.glide.ShowImageUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by soft_zzc on 2017/11/26.
 */

public class ProductListAdapter extends BaseAdapter<ProductListModel.DataBean.GoodsBean> {


    @BindView(R.id.card_top_pic)
    ImageView cardTopPic;
    @BindView(R.id.rent_item_list_text1)
    TextView rentItemListText1;
    @BindView(R.id.rent_item_list_text2)
    TextView rentItemListText2;
    @BindView(R.id.Re_card_hot_jump_into)
    LinearLayout ReCardHotJumpInto;
    private Logger log = LoggerFactory.getLogger(this.getClass().getName());
    private CardHotModel cardHotModel;

    public ProductListAdapter(Context context) {
        super(context);
        log.debug("jump into CardHotAdapter");
    }


    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.rent_item_list, null);
            viewHolder = new ViewHolder(convertView, position, mContext);
            viewHolder.setData(mList.get(position));
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            viewHolder.setData(mList.get(position));
        }
        return convertView;
    }

    static class ViewHolder {

        @BindView(R.id.card_top_pic)
        ImageView cardTopPic;
        @BindView(R.id.rent_item_list_text1)
        TextView rentItemListText1;
        @BindView(R.id.rent_item_list_text2)
        TextView rentItemListText2;
        @BindView(R.id.Re_card_hot_jump_into)
        LinearLayout ReCardHotJumpInto;
        private Context context;
        int position;
        private String uil;

        ViewHolder(View view, int position, Context context) {
            this.position = position;
            this.context = context;
            ButterKnife.bind(this, view);
        }

        public void setData(final ProductListModel.DataBean.GoodsBean goodsBean) {
            ShowImageUtils.showImageView(App.getContext(),cardTopPic,goodsBean.getGoodsCoverImage());
            rentItemListText1.setText(goodsBean.getGoodsName());
            rentItemListText2.setText("￥"+goodsBean.getPrice()+"/月起");

            ReCardHotJumpInto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(context, ProductDetailsActivity.class);
                    intent.putExtra(Constants.GOODS_ID,goodsBean.getId());
                    context.startActivity(intent);
                    //Toast.makeText(context, "1111111", Toast.LENGTH_SHORT).show();
                }
            });

           /* relativeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //实例化WebView对象
                    WebView webview = new WebView(context);
                    //设置WebView属性，能够执行Javascript脚本
                    webview.getSettings().setJavaScriptEnabled(true);
                    //加载需要显示的网页
                    webview.loadUrl(cardsBean.getLink());
                }
            });*/
        }
    }

}
